import uuid
from datetime import datetime

from django.db import models


# Create your models here.
def upload_to(instance, filename):
    print(instance)
    # 分割逗号
    ext = filename.split('.')[-1]
    filename = f'{uuid.uuid4()}.{ext[1]}'
    now = datetime.now()
    return f"avatar/{now.year}/{now.month}/{now.day}/{filename}"


# 类型
class Type(models.Model):
    name = models.CharField(max_length=32, verbose_name='类型名称')

    class Meta:
        db_table = 'type'
        verbose_name = '类型'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


# 公司
class Company(models.Model):
    # 头像
    avatar = models.ImageField(upload_to=upload_to, verbose_name='头像', null=True, blank=True)
    # 工号
    job_number = models.CharField(max_length=32, verbose_name='工号')
    # 部门
    department = models.CharField(max_length=32, verbose_name='部门')
    # 手机号
    phone = models.CharField(max_length=11, verbose_name='手机号')
    # 职位
    position = models.CharField(max_length=32, verbose_name='职位')
    # 类型
    type = models.ForeignKey(Type, on_delete=models.CASCADE, verbose_name='类型')
    # 证件类型
    card_type = models.CharField(max_length=32, verbose_name='证件类型')
    # 身份证号
    card_number = models.CharField(max_length=32, verbose_name='身份证号')
    # 入职日期
    entry_date = models.DateField(verbose_name='入职日期')
    class Meta:
        db_table = 'company'
        verbose_name = '公司'
        verbose_name_plural = verbose_name
    def __str__(self):
        return self.job_number
